//
//  HNShareView.m
//  HappyNews
//
//  Created by baiping on 16/1/15.
//  Copyright © 2016年 BPWBANP. All rights reserved.
//

#import "HNShareView.h"

@interface HNShareView()

@property (nonatomic, strong) NSArray *imageNameArr;

@property (nonatomic, strong) NSArray *titleArr;

@property (nonatomic, strong) NSArray *imageHightNameArr;

@end

@implementation HNShareView

- (NSArray *)titleArr{
    
    if (!_titleArr) {
        
        _titleArr = @[@"微信好友" , @"QQ", @"新浪微博", @"人人", @"豆瓣", @"信息", @"腾新微博", @"印象笔记"];
        
    }
    return _titleArr;
    
}

- (NSArray *)imageNameArr{
    
    if (!_imageNameArr) {
        
        _imageNameArr = @[@"Share_WeChat", @"Share_QQ", @"Share_Sina", @"Share_Renren",  @"share_douban-2", @"Share_Message", @"Share_Tencent",@"Share_Evernote"];

    }
    return _imageNameArr;
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
    [self addSubviews];

    }
    
    return self;
}

- (void)addSubviews{
    
    
    CGFloat btnW = 60;
    
    CGFloat BtnH = 60;
    
    NSInteger totalIndex = 8;
    
    for (int i = 0; i < totalIndex; i++) {
        
        NSInteger row  = i / 4;
        
        NSInteger list = i % 4;
        
        CGFloat btnMargin = (kScreenWidth - btnW * 4 - 20 * 2) / 3;
        
        HNHomeShareSubView *btn = [[HNHomeShareSubView alloc]initWithFrame:CGRectMake(20 + (btnW + btnMargin) * list, 40 + (BtnH + 30) * row , btnW, BtnH)];
        
        btn.tag = i + 100;
        
        // 给按钮添加内容
        btn.name.text = self.titleArr[i];
        
        [btn.shareButton setImage:[UIImage imageNamed:self.imageNameArr[i]] forState:(UIControlStateNormal)];
        
        [self addSubview:btn];
        
    }
    [self shareSubViewByTag:100 btn:_weiXinBtn];
    
    [self shareSubViewByTag:101 btn:_QQBtn];
    
    [self shareSubViewByTag:102 btn:_sinaBtn];
    
    [self shareSubViewByTag:103 btn:_renRenBtn];
    
    [self shareSubViewByTag:104 btn:_douBanBtn];
    
    [self shareSubViewByTag:105 btn:_messageBtn];
    
    [self shareSubViewByTag:106 btn:_tXWeiBoBtn];
    
    [self shareSubViewByTag:107 btn:_yiXinBtn];
    
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth / 2 - 70, 10, 140, 30)];
    
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    
    _titleLabel.font = [UIFont systemFontOfSize:17];
    
    _titleLabel.text = @"分享这篇内容";
    
    [self addSubview:_titleLabel];
    
    _collectBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    
    _collectBtn.frame = CGRectMake(20, 220,kScreenWidth - 40 , 30);
    
    [_collectBtn setTitle:@"收藏" forState:(UIControlStateNormal)];
    
    _collectBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [_collectBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    _collectBtn.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:_collectBtn];
    
    _cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(_collectBtn.left, _collectBtn.bottom + 20, _collectBtn.width, _collectBtn.height)];
    
    [_cancelBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [_cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)];
    _cancelBtn.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:_cancelBtn];
    
}

// 根据tag值来对应按钮
- (void)shareSubViewByTag:(NSInteger)tag btn:(HNHomeShareSubView *)btn{
    
   
    
    for (HNHomeShareSubView *subBtn in self.subviews) {
        
        // btn传进来的时候只是一个指针 就是利用这个方法给他赋值的
        if ([subBtn isKindOfClass:[HNHomeShareSubView class]]) {
            
            if (subBtn.tag == tag) {
                
                btn = subBtn;
                
            }
        }

    }
   
}







@end
